<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改问答管理')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: jquery-smartwizard-css"/>
    <link rel="stylesheet" href="/js/kindeditor/themes/default/default.css"/>
    <script charset="utf-8" src="/js/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="/js/kindeditor/lang/zh-CN.js"></script>
    <style>
        .qustitle {
            text-align: left;
        }

        .quespan {
            color: #00687D;
        }

        .white-bg {
            padding: 32px !important;
        }

        .layui-tab {
            position: relative;
        }

        .layui-btn {
            background: #E6F8FA !important;
            color: #02B7CA !important;
            position: absolute;
            right: 0px;
            top: -10px;
            z-index: 99;
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-question-edit" th:object="${question}">
        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true"> 基本信息</a>
            </li>
            <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">其他信息</a>
            </li>
        </ul>
        <div class="contain tab-content">
            <div id="tab-1" class="tab-pane active" style="padding: 20px">
            <div class="form-group">
                <div class="col-sm-12">
                    <input name="id" th:field="*{id}" type="hidden">
                    <label class="col-sm-1 control-label">问题标题</label>
                    <div class="col-sm-11">
                        <input name="questionTitle" th:field="*{questionTitle}" class="form-control" type="text">
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label is-required">请选择药品</label>
                    <div class="col-sm-10">
                        <select class="form-control select2-multiple" name="drugId" id="pids"
                                th:with="type=${@commonService.drugKeyAndValue()}"
                                onchange="changeDrug()"
                                th:field="*{drugId}"
                                data-placeholder="请选择药品" lay-search="">
                            <option th:each="dict : ${type}" th:text="${dict.vals}"
                                    th:value="${dict.keyName}"></option>
                        </select>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label is-required">选择科目</label>
                    <!--th:field="*{subjectsName}"-->
                    <div class="col-sm-10">
                        <select class="form-control select2-multiple" id="pid"
                                th:with="type=${@commonService.selectDiseaseByPid('0')}"
                                onchange="changePDisease()"
                                th:field="*{subjectsId}"
                                name="subjectsId"
                                data-placeholder="请选择科目">
                            <option value="">请选择科目</option>
                            <option th:each="dict : ${type}" th:text="${dict.name}"
                                    th:value="${dict.id}"></option>
                        </select>
                    </div>
                </div>

            </div>
            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label is-required">选择疾病</label>
                    <div class="col-sm-10">
                        <select class="form-control select2-multiple" id="cid"
                                name="diseaseId"
                                data-placeholder="请选择疾病">
                            <option value="">请选择疾病</option>
                        </select>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label">问题类型</label>
                    <div class="col-sm-10">
                        <select name="questionTypeId" class="form-control m-b" th:field="*{questionTypeId}"
                                th:with="type=${@dict.getType('drug_article')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>

<!--            <div class="form-group">-->
<!--                <div class="col-sm-6">-->
<!--                    <label class="col-sm-2 control-label is-required">用户性别:</label>-->
<!--                    <div class="col-sm-10">-->
<!--                        <div class="radio-box" th:each="dict : ${@dict.getType('sys_user_sex')}">-->
<!--                            <input type="radio" th:id="${'status_' + dict.dictCode}" name="questionSex"-->
<!--                                   th:value="${dict.dictValue}" required th:field="*{questionSex}">-->
<!--                            <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
<!--                <div class="col-sm-6">-->
<!--                    <label class="col-sm-2 control-label is-required">用户年龄</label>-->
<!--                    <div class="col-sm-10">-->
<!--                        <input name="age" th:field="*{questionAge}" placeholder="请输入用户年龄" class="form-control" min="0"-->
<!--                               type="number" required>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->

<!--            <div class="form-group">-->
<!--                <label class="col-sm-1 control-label is-required">问题内容</label>-->
<!--                <div class="col-sm-11">-->
<!--                    <input type="hidden" class="form-control" required>-->
<!--                    <script id="questionContent" name="questionContent" type="text/plain"></script>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-1 control-label is-required">回答内容</label>
                <div class="col-sm-11">
                    <input type="hidden" class="form-control" required>
                    <script class="checkContent" id="answerContent" name="answerContent" type="text/plain"></script>
                </div>
            </div>

            <div class="form-group">
<!--                <div class="col-sm-6">-->
<!--                    <label class="col-sm-2 control-label">网页标题</label>-->
<!--                    <div class="col-sm-10">-->
<!--                        <input name="webpagetitle" class="form-control" th:field="*{webpagetitle}" type="text"-->
<!--                               placeholder="请输入网页标题">-->
<!--                    </div>-->
<!--                </div>-->
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label">网页关键词</label>
                    <div class="col-sm-10">
                        <input name="webpagekeywords" class="form-control" th:field="*{webpagekeywords}" type="text"
                               placeholder="请输入网页关键词">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12">
                    <label class="col-sm-1 control-label">网页详情</label>
                    <div class="col-sm-11">
                            <textarea class="form-control" name="webpagedescription" th:field="*{webpagedescription}"
                                      placeholder="请输入网页描述"></textarea>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-12">
                    <label class="col-sm-1 control-label">免责声明</label>
                    <div class="col-sm-11">
                        <textarea name="warmPrompt" class="form-control">[[*{warmPrompt}]]</textarea>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-12">
                    <label class="col-sm-1 control-label">参考资料</label>
                    <div class="col-sm-11">
                        <textarea name="referenceMaterial" class="form-control">[[*{referenceMaterial}]]</textarea>
                    </div>
                </div>
            </div>

            </div>
            <div id="tab-2" class="tab-pane " style="padding: 20px;">
                <div class="btn-group-sm" style="display: flex; margin-bottom: 30px" id="toolbar" role="group">
                    <a class="btn btn-newadd" onclick="addLi('doctor','que',this)">
                        医生问
                    </a>
                    <a class="btn btn-newadd" onclick="addLi('doctor','ans',this)">
                        医生答
                    </a>
                    <a class="btn btn-newadd" onclick="addLi('patient','que',this)">
                        患者问
                    </a>
                    <a class="btn btn-newadd" onclick="addLi('patient','ans',this)">
                        患者答
                    </a>

                </div>
                <div class="ibox">
                    <div class="ibox-content">
                        <ul class="sortable-list connectList agile-list" id="exchange_box">

                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="col-sm-1"></div>

</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js"/>
<!--<script src="//unpkg.com/layui@2.8.0/dist/layui.js"></script>-->
<script src="/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
<script src="/ueditor/ueditor.all.js" type="text/javascript" charset="utf-8"></script>
<script src="/ueditor/lang/zh-cn/zh-cn.js" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/js/jquery-ui-1.10.4.min.js}"></script>
<script th:inline="javascript">
    $(document).ready(function () {
        $(".sortable-list").sortable({connectWith: ".connectList"}).disableSelection()
    });
    var prefix = ctx + "yibanlv/question";
    var catelist = []
    let diseaseId = [[${question}]].diseaseId
    let qaExchangeList = [[${question}]].qaExchangeList
    var cidarr = diseaseId ? diseaseId.split(',') : []
    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;
        // select 事件
        form.on('select(demo-select-filter)', function (data) {
            var elem = data.elem; // 获得 select 原始 DOM 对象
            var value = data.value; // 获得被选中的值
            var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象

            layer.msg(this.innerHTML + ' 的 value: ' + value); // this 为当前选中 <option> 元素对象
        });
    });
    $("#form-question-edit").validate({
        focusCleanup: true
    });

    $(document).ready(function () {
        // parent.$('body').find('.layui-layer-max').click()
        let pidarr = []
        $.ajax({
            url: '/yibanlv/disease/list',
            type: 'POST',
            async: false,
            success: function (data) {
                catelist = data
                let items = data.find(item => {
                    for (let i = 0; i < cidarr.length; i++) {
                        if (cidarr[i] == item.id) {
                            pidarr.push(item.pid)
                        }
                    }
                })
                $('#pid').val(pidarr)
                if (0 < pidarr.length){
                    $('#pid').trigger('change')
                }
            }
        });

        qaExchangeList.forEach(item=>{
            queShow(item.flag,item.type,item.content)
        })


    })

    function queShow(flag,type,content) {
        //最终拼接成的html代码
        var html="";
        //按钮名称 = 谁提问或谁回答
        var name = "";
        if("doctor"==flag){
            if("que"==type){
                name = "医生问"
            }else{
                name = "医生答"
            }
        }else{
            if("que"==type){
                name = "患者问"
            }else{
                name = "患者答"
            }
        }

        //问题用input框，回答用textarea
        var str = "";
        //左侧标识，蓝色为问题，绿色为回答
        var icon = "";
        if("que"===type){
            str = "<input class='form-control' name='content' value='"+content+"'>"
            icon = "info-element"
        }else{
            str = "<textarea class='form-control' name='content'>"+content+"</textarea>"
            icon = "success-element"
        }
        html+="<li class='"+icon+"'>"
            +"<label>"+name+"</label>"
            +"<a href = '#' class='pull-right btn btn-xs btn-white' onClick = 'removeLi(this)' > 删除 </a>"
            +str
            +"<input type='hidden' class='form-control' value='"+type+"'  name='type'>"
            +"<input type='hidden' class='form-control' value='"+flag+"'  name='flag'>"
            +"</li>"

        $("#exchange_box").append(html);
    }

    //富文本
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function (action) {
        if (action == 'uploadimage' || action == 'uploadscrawl') {
            return '/common/upload';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }
    var ue = UE.getEditor('questionContent', {
        autoHeightEnabled: false,//是否自动长高
        autoFloatEnabled: true,//是否保持toolbar的位置不动
        scaleEnabled: true,//是否可以拉伸长高
        initialFrameWidth: 'auto',//初始化编辑器宽度
        initialFrameHeight: 300,//初始化编辑器高度
    });
    ue.ready(function () {
        ue.execCommand("insertHtml", [[${question}]].questionContent);//富文本回显
    })

    var answerue = UE.getEditor("answerContent", {
        autoHeightEnabled: false,//是否自动长高
        autoFloatEnabled: true,//是否保持toolbar的位置不动
        scaleEnabled: true,//是否可以拉伸长高
        initialFrameWidth: 'auto',//初始化编辑器宽度
        initialFrameHeight: 300,//初始化编辑器高度
    });
    answerue.ready(function () {
        answerue.execCommand("insertHtml", [[${question}]].answers[0].answerContent);//富文本回显
    })

    function submitHandler() {
        var myForm = $('#form-question-edit');
        var formData = myForm.serializeArray();
        var json = {};
        $.each(formData, function (k, v) {
            json[v.name] = v.value;
        });
        let answerarr = [];
        let answer = {
            answerContent: answerue.getContent(),
            createBy:[[${question}]].answers[0] ? [[${question}]].answers[0].createBy : '',
            createTime:[[${question}]].answers[0] ? [[${question}]].answers[0].createTime : '',
            delFlag:[[${question}]].answers[0] ? [[${question}]].answers[0].delFlag : '',
            id:[[${question}]].answers[0] ? [[${question}]].answers[0].id : null,
            questionid:[[${question}]].answers[0] ? [[${question}]].answers[0].questionid : [[${question}]].id,
            remark:[[${question}]].answers[0] ? [[${question}]].answers[0].remark : '',
            updateBy:[[${question}]].answers[0] ? [[${question}]].answers[0].updateBy : '',
            updateTime:[[${question}]].answers[0] ? [[${question}]].answers[0].updateTime : '',
        }
        answerarr.push(answer);
        json.answers = answerarr
        /*----------------------------------*/
        //
        //     var count = 0;
        //     var idCount = 0;
        //
        //     idList.forEach(id => {
        //         var answer = {}
        //         answer.id = id;
        //     answer.answerContent = getvalues(id) + "";
        //     if(getvalues(id) + "" === "[object Object]"){
        //         count++;
        //     }
        //     answer.questionid = [[${question.id}]];
        //     params.push(answer)
        //     idCount++;
        // })
        //     /*if ($.validate.form()) {
        //         $.operate.save(prefix + "/batchAddOrEdit", $('#form-hospital-add').serialize());
        //     }*/
        //
        //     json.answers=params
        if (!json.questionContent) {
            $.modal.msgWarning("请填写问题内容！");
            return;
        }
        if (json.answers[0].answerContent == '') {
            $.modal.msgWarning("请填写回答内容！");
            return;
        }
        let acArr = [];
        $('#exchange_box li').each(function() {
            $(this).find('input').val()
            var flag = $(this).find('input[name="flag"]').val();
            var type = $(this).find('input[name="type"]').val();
            var content = "";
            if("que"===type){
                content = $(this).find('input[name="content"]').val();
            }else {
                content = $(this).find('textarea').val();
            }
            var obj = {}
            obj.flag = flag;
            obj.type = type;
            obj.content = content;
            acArr.push(obj);
        });
        json.qaExchangeList = acArr
        var value = JSON.stringify(json)

        save1(prefix + "/edit", value);
    }

    function save1(url, data, callback) {
        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            headers: {
                'Content-Type': 'application/json;charset=utf8'
            },
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍候...");
                $.modal.disable();
            },
            success: function (result) {
                if (typeof callback == "function") {
                    callback(result);
                }
                $.operate.successCallback(result);
            }
        };
        $.ajax(config)
    }

    // //科目疾病二级联动
    // function changePDisease() {
    //     let cidSelected = $("#pid").val();
    //     let cDiseaseHtml = ""
    //     cDiseaseHtml += "<optgroup>";
    //     for(let a=0;a<cidarr.length;a++) {
    //         let iscid=cidarr[a]
    //         catelist.forEach(function (item) {
    //             for (let i = 0; i < cidSelected.length; i++) {
    //                 if (item.pid == cidSelected[i]) {
    //                     if (item.id==iscid){
    //                         cDiseaseHtml += `<option value="${item.id}" selected = 'selected'>${item.name}</option>`
    //                         continue
    //                     }else{
    //                         cDiseaseHtml += `<option value="${item.id}" >${item.name}</option>`
    //                     }
    //                 }
    //             }
    //         })
    //     }
    //     cDiseaseHtml += '</optgroup>'
    //     $("#cid").html(cDiseaseHtml);
    //     $('#cid').trigger('change');
    // }
    //科目疾病二级联动
    function changePDisease() {
        let cidSelected = $("#pid").val();
        let cDiseaseHtml = ""
        catelist.forEach(function (item) {
            if (item.pid == cidSelected) {
                cDiseaseHtml += `<option value="${item.id}" ${item.id == diseaseId ? selected = 'selected' : ''}>${item.name}</option>`
            }
        })
        $("#cid").html(cDiseaseHtml);
        $('#cid').trigger('change');

    }

    // 药品变化时关联疾病
    function changeDrug() {
        let drugId = $('#pids').val()
        if(null != drugId && '' != drugId){
            $.ajax({
                url: "/api/drug/getDrugById/" + drugId,
                type: "get",
                success: res => {
                    if('1' == res.code){
                        var cid = "<option value="+res.data.diseaseList[0].diseaseId+">"+res.data.diseaseList[0].diseaseName+"</option>"
                        var pid = "<option value="+res.data.diseaseList[0].subjectsId+">"+res.data.diseaseList[0].pidName+"</option>"

                        $("#cid").html(cid);
                        $("#pid").html(pid);
                    }
                }
            })
        }
    }

    /*---------------------------*/

    /*提交时所有的id*/
    var idList = [];

    /*返回参数集合*/
    var params = [];

    /*layui的方法*/
    layui.use(function () {
        /*编辑框全屏*/
        parent.$('body').find('.layui-layer-max').click()

        if ([[${answers}]] == null || [[${answers}]].length == 0) {
            window.addtable('test-handle', {
                title: '回答1',
                content: '8',
                id: new Date().getTime()
            })
            // element.tabChange('test-handle', "8");


        }
        $("ul li").first().click()
        /*初始化点击第一个选项卡*/


        /*初始化调用*/
    });

    var element = layui.element;
    var util = layui.util;
    // 普通事件
    util.on('lay-on', {

        tabAdd: function () {
            // 新增一个 tab 项
            var count = $(".layui-tab-title li").length + 1;
            window.addtable('test-handle', {
                title: '回答' + count,
                content: count + 9999999,
                id: new Date().getTime()
            })

            if (count == 1) {
                $("#top_menu li:first").attr("lay-id", "1684461945054")

                layui.element.tabChange('test-handle', "1684461945054");
            }

        },

        tabDelete: function (othis) {
            // 删掉指定 tab 项
            element.tabDelete('test-handle', '44');
            othis.addClass('layui-btn-disabled');
        },

        tabChange: function () {
            // 切换到指定 tab 项
            element.tabChange('test-handle', '8');
        },

    });


    //外部Tab新增
    addtable = function (filter, options) {
        var TITLE = '.layui-tab-title'
            , tabElem = $('.layui-tab[lay-filter=' + filter + ']')
            , titElem = tabElem.children(TITLE)
            , barElem = titElem.children('.layui-tab-bar')
            , contElem = tabElem.children('.layui-tab-content')
            , call = {
            //Tab 点击
            tabClick: function (e, index, liElem, options) {
                options = options || {};
                var othis = liElem || $(this)
                    , index = index || othis.parent().children('li').index(othis)
                    , parents = options.headerElem ? othis.parent() : othis.parents('.layui-tab').eq(0)
                    ,
                    item = options.bodyElem ? $(options.bodyElem) : parents.children('.layui-tab-content').children('.layui-tab-item')
                    , elemA = othis.find('a')
                    , isJump = elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank' //是否存在跳转
                    , unselect = typeof othis.attr('lay-unselect') === 'string' //是否禁用选中
                    , filter = parents.attr('lay-filter');

                //执行切换
                if (!(isJump || unselect)) {
                    othis.addClass('layui-this').siblings().removeClass('layui-this');
                    item.eq(index).addClass('layui-show').siblings().removeClass('layui-show');
                }

                layui.event.call(this, 'element', 'tab(' + filter + ')', {
                    elem: parents
                    , index: index
                });
            }

            //Tab删除
            , tabDelete: function (e, othis) {
                var li = othis || $(this).parent(), index = li.index()
                    , parents = li.parents('.layui-tab').eq(0)
                    , item = parents.children('.layui-tab-content').children('.layui-tab-item')
                    , filter = parents.attr('lay-filter');

                if (li.hasClass('layui-this')) {
                    if (li.next()[0]) {
                        call.tabClick.call(li.next()[0], null, index + 1);
                    } else if (li.prev()[0]) {
                        call.tabClick.call(li.prev()[0], null, index - 1);
                    }
                }

                li.remove();
                item.eq(index).remove();
                setTimeout(function () {
                    call.tabAuto();
                }, 50);

                layui.event.call(this, 'element', 'tabDelete(' + filter + ')', {
                    elem: parents
                    , index: index
                });
            }

            //Tab自适应
            , tabAuto: function () {
                var SCROLL = 'layui-tab-scroll', MORE = 'layui-tab-more', BAR = 'layui-tab-bar'
                    , CLOSE = 'layui-tab-close', that = this;

                $('.layui-tab').each(function () {
                    var othis = $(this)
                        , title = othis.children('.layui-tab-title')
                        , item = othis.children('.layui-tab-content').children('.layui-tab-item')
                        , STOPE = 'lay-stope="tabmore"'
                        ,
                        span = $('<span class="layui-unselect layui-tab-bar" ' + STOPE + '><i ' + STOPE + ' class="layui-icon">&#xe61a;</i></span>');

                    if (that === window && device.ie != 8) {
                        call.hideTabMore(true)
                    }

                    //允许关闭
                    if (othis.attr('lay-allowClose')) {
                        title.find('li').each(function () {
                            var li = $(this);
                            if (!li.find('.' + CLOSE)[0]) {
                                var close = $('<i class="layui-icon layui-icon-close layui-unselect ' + CLOSE + '"></i>');
                                close.on('click', call.tabDelete);
                                li.append(close);
                            }
                        });
                    }

                    if (typeof othis.attr('lay-unauto') === 'string') return;

                    //响应式
                    if (title.prop('scrollWidth') > title.outerWidth() + 1) {
                        if (title.find('.' + BAR)[0]) return;
                        title.append(span);
                        othis.attr('overflow', '');
                        span.on('click', function (e) {
                            title[this.title ? 'removeClass' : 'addClass'](MORE);
                            this.title = this.title ? '' : '收缩';
                        });
                    } else {
                        title.find('.' + BAR).remove();
                        othis.removeAttr('overflow');
                    }
                });
            }
            //隐藏更多Tab
            , hideTabMore: function (e) {
                var tsbTitle = $('.layui-tab-title');
                if (e === true || $(e.target).attr('lay-stope') !== 'tabmore') {
                    tsbTitle.removeClass('layui-tab-more');
                    tsbTitle.find('.layui-tab-bar').attr('title', '');
                }
            }

            //点击菜单 - a标签触发
            , clickThis: function () {
                var othis = $(this)
                    , parents = othis.parents(NAV_ELEM)
                    , filter = parents.attr('lay-filter')
                    , parent = othis.parent()
                    , child = othis.siblings('.' + NAV_CHILD)
                    , unselect = typeof parent.attr('lay-unselect') === 'string'; //是否禁用选中

                if (!(othis.attr('href') !== 'javascript:;' && othis.attr('target') === '_blank') && !unselect) {
                    if (!child[0]) {
                        parents.find('.' + THIS).removeClass(THIS);
                        parent.addClass(THIS);
                    }
                }

                //如果是垂直菜单
                if (parents.hasClass(NAV_TREE)) {
                    child.removeClass(NAV_ANIM);

                    //如果有子菜单，则展开
                    if (child[0]) {
                        parent[child.css('display') === 'none' ? 'addClass' : 'removeClass'](NAV_ITEM + 'ed');
                        if (parents.attr('lay-shrink') === 'all') {
                            parent.siblings().removeClass(NAV_ITEM + 'ed');
                        }
                    }
                }

                layui.event.call(this, 'element', 'nav(' + filter + ')', othis);
            }
            //折叠面板
            , collapse: function () {
                var othis = $(this), icon = othis.find('.layui-colla-icon')
                    , elemCont = othis.siblings('.layui-colla-content')
                    , parents = othis.parents('.layui-collapse').eq(0)
                    , filter = parents.attr('lay-filter')
                    , isNone = elemCont.css('display') === 'none';

                //是否手风琴
                if (typeof parents.attr('lay-accordion') === 'string') {
                    var show = parents.children('.layui-colla-item').children('.' + SHOW);
                    show.siblings('.layui-colla-title').children('.layui-colla-icon').html('&#xe602;');
                    show.removeClass(SHOW);
                }

                elemCont[isNone ? 'addClass' : 'removeClass'](SHOW);
                icon.html(isNone ? '&#xe61a;' : '&#xe602;');

                layui.event.call(this, 'element', 'collapse(' + filter + ')', {
                    title: othis
                    , content: elemCont
                    , show: isNone
                });
            }
        }
            , li = '<li' + function () {
            var layAttr = [];
            layui.each(options, function (key, value) {
                if (/^(title|content)$/.test(key)) return;
                layAttr.push('lay-' + key + '="' + value + '"');
            });
            if (layAttr.length > 0) layAttr.unshift(''); //向前插，预留空格
            return layAttr.join(' ');
        }() + '>' + (options.title || 'unnaming') + '</li>';

        barElem[0] ? barElem.before(li) : titElem.append(li);
        contElem.append('<div class="layui-tab-item"><input type="hidden" id="box"><textarea class="checkContent" id="' + (options.content || '') + '" name="answerContent" style="width: 100%; height:400px;visibility:hidden;" th:id=${temp.id} th:utext=${temp.answerContent}></textarea></div>');
        call.hideTabMore(true);
        call.tabAuto();
        idList.push(options.content)
        return this
    }

    /*调用富文本*/


    /*确定提交*/
    /*function submitHandler() {
        idList.forEach(id => {
            var answer = {}
            answer.id = id;
        answer.answerContent = getvalues(id);
        answer.questionid = [[${question.id}]];
        params.push(answer)
    })
        /!*if ($.validate.form()) {
            $.operate.save(prefix + "/batchAddOrEdit", $('#form-hospital-add').serialize());
        }*!/
        var data =JSON.stringify(params);
        $.ajax({
            url: '/yibanlv/answer/batchAddOrEdit',
            type: 'POST',
            headers: {
                'Content-Type': 'application/json;charset=utf8'
            },
            async: false,
            data: data,
            success: function (data) {
                $.modal.msgReload(data.msg);
            }
        })
    }*/

    /*获取到所有的富文本id*/
    function getvalues(id) {
        id = "#" + id;
        var str = $(id).summernote('code');
        return str
    }

    function addLi(flag,type,e) {
        //最终拼接成的html代码
        var html="";
        //按钮名称 = 谁提问或谁回答
        var name = e.innerText;
        //问题用input框，回答用textarea
        var str = "";
        //左侧标识，蓝色为问题，绿色为回答
        var icon = "";
        if("que"===type){
            str = "<input class='form-control' name='content'>"
            icon = "info-element"
        }else{
            str = "<textarea class='form-control' name='content'></textarea>"
            icon = "success-element"
        }
        html+="<li class='"+icon+"'>"
            +"<label>"+name+"</label>"
            +"<a href = '#' class='pull-right btn btn-xs btn-white' onClick = 'removeLi(this)' > 删除 </a>"
            +str
            +"<input type='hidden' class='form-control' value='"+type+"'  name='type'>"
            +"<input type='hidden' class='form-control' value='"+flag+"'  name='flag'>"
            +"</li>"

        $("#exchange_box").append(html);
    }

    function removeLi(e) {
        $(e).parent().remove();
    }

</script>
</body>
</html>